/**
 * 用户档案里面项目列表
 */

function project_info1() {
    var _this = this;
    var page;
    _this.page_size = 10;
    _this.type;
    _this.projectName;

    _this.init = function (page_person, type, projectName) {
        page = page_person;
        _this.initTable();
        _this.type = type;
        _this.projectName = projectName;

    };

    _this.initTable = function () {
        var list_url = appPath + "/admin/dossier/projectOffline/user_list";
        page.init("project_info_form", list_url, "project_info_table", "project_info_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function (dataList) {
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for (var i = 0; i < len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td>' + (i + 1) + '</td>';
                inner += '<td>' + item['user_name'] + '</td>';

                var dept_name = item['department_name'];
                if (dept_name == '' || dept_name == undefined || dept_name == null) {
                    inner += "<td>\</td>";
                } else {
                    inner += '<td>' + item['department_name'] + '</td>';
                }
                inner += '<td>' + TimeUtil.getHouAndMinAndSec(item['requireTime'] * 60) + '</td>';
                inner += '<td>' + TimeUtil.getHouAndMinAndSec(item['study_time']) + '</td>';
                var score = item['score'];
                if (score == '' || score == undefined) {
                    score = '\\';
                }
                inner += '<td>' + score + '</td>';
                var isPassed = item['is_passed'];

                if (isPassed == 1) {
                    inner += '<td>合格</td>';
                } else if (isPassed == 2) {
                    inner += '<td>不合格</td>';
                }else if(isPassed == '' || isPassed == undefined){
                    inner += '<td>未考试</td>'
                }

                inner += '</tr>';
            }

            var iObj = $(inner);

            return iObj;
        };
    };

    _this.search = function () {
        _this.initTable();
    };

    _this.searchAll = function () {
        $("#project_info_form").find("input[name=user_name]").val("");
        $("#project_info_form").find("input[name=dept_name]").val("");
        $("#project_info_form").find("input[name=role_name]").val("");
        _this.initTable();
    };

    _this.export_info = function () {
        if (page.count != 0) {
            _this.to_export();
        } else {
            layer.msg("没有可以导出的数据！");
        }
    };
    /**
     * checkbox 点击事件
     * @param selectedNode
     */
    var userIdAll = [];
    var object = {};
    var exam_status;
    /**
     * 全选事件
     */
    $("#checkAll").click(function () {
            if (this.checked) {
                $("#project_info_table :checkbox").prop("checked", true);

                $("#project_info_table :checkbox").each(function () {
                    if (!object[$(this).val()]) {
                        object[$(this).val()] = 1;
                        userIdAll.push($(this).val());
                        exam_status = $(this).attr("exam_status") == "1"?false:true;
                    }
                });

            } else {
                $("#project_info_table :checkbox").prop("checked", false);
                if (userIdAll.length > 0) {
                    for (var a = 0; a < userIdAll.length; a++) {
                        $("#project_info_table :checkbox").each(function () {
                            if ($(this).val() === userIdAll[a]) {
                                delete object[$(this).val()];
                                userIdAll.splice(a, 1);
                            }
                        })
                    }
                }
            }
        }
    );
    _this.to_export = function () {
        //var checkRes = _this.getCheckedRows_ids();

        var project_id = $("#project_info_form").find("input[name=project_id]").val();
        console.log("数据长度："+userIdAll);
        if (userIdAll.length>0) {
            if (exam_status == false) {       //所选 都没有考试记录
                layer.msg("没有考试记录可导出！");
                return;
            }
            var backend_url = $("#backendUrl").val();
            window.open(backend_url + '/export/export_exam_record?userIds=' + userIdAll + "&project_id=" + project_id + "&project_name=" + _this.projectName);
        } else {
            layer.msg("请选择需导出成绩的人员！");
        }
    };


    _this.ajax = function (url, param, type) {
        var result;
        $.ajax({
            url: url,
            async: false,
            type: 'post',
            data: param,
            success: function (data) {
                result = data;
            }
        });
        return result;
    };

}

var project_info1 = new project_info1();